package com.zjx.shop.ware.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjx.shop.common.utils.PageParams;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjx.shop.common.utils.PageUtils;
import com.zjx.shop.ware.dao.WareInfoDao;
import com.zjx.shop.ware.entity.WareInfoEntity;
import com.zjx.shop.ware.service.WareInfoService;
import org.springframework.util.StringUtils;


@Service("wareInfoService")
public class WareInfoServiceImpl extends ServiceImpl<WareInfoDao, WareInfoEntity> implements WareInfoService {

    @Override
    public PageUtils queryPage(PageParams params) {
        QueryWrapper<WareInfoEntity> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(params.getKey())){
            wrapper.
                    like("name",params.getKey()).or()
                    .like("address",params.getKey()).or()
                    .like("areacode",params.getKey());
        }
        IPage<WareInfoEntity> page = this.page(
                new Page<>(params.getPage(),params.getSize()),
                wrapper
        );

        return new PageUtils(page.getCurrent(),page.getSize(),(long) page.getRecords().size(),page.getRecords());
    }

}